#include "add_cmd_dialog.hpp"
#include <QVBoxLayout>
#include <QPushButton>

AddCmdDiaglog::AddCmdDiaglog(QWidget *parent) : QDialog(parent)
{
    setWindowTitle("添加命令");
    resize(300, 150);

    QVBoxLayout *layout = new QVBoxLayout(this);

    buttonNameEdit = new QLineEdit(this);
    buttonNameEdit->setPlaceholderText("请输入按键名");
    buttonNameEdit->setAttribute(Qt::WA_InputMethodEnabled, true);
    buttonNameEdit->setFocusPolicy(Qt::WheelFocus);
    layout->addWidget(buttonNameEdit);

    commandEdit = new QLineEdit(this);
    commandEdit->setPlaceholderText("请输入命令");
    layout->addWidget(commandEdit);

    QPushButton *confirmButton = new QPushButton("确认", this);
    layout->addWidget(confirmButton);

    connect(confirmButton, &QPushButton::clicked, this, &AddCmdDiaglog::onConfirmClicked);
}

void AddCmdDiaglog::onConfirmClicked()
{
    buttonName = buttonNameEdit->text();
    command = commandEdit->text();

    if(buttonName.isEmpty() || command.isEmpty()) {
        QMessageBox::warning(this, "警告", "请输入完整的按键名和命令！");
        return;
    }

    accept();
}